package src.java.medium;

public class Solution238 {
//    public static int getNumber(int[] nums, int index) {
//        int number = 1;
//        for (int i = 0; i < nums.length; i++) {
//            if (i == index) {
//                continue;
//            }
//            number *= nums[i];
//        }
//        return number;
//    }

    public int[] productExceptSelf(int[] nums) {
        int length = nums.length;
        int[] answer = new int[length];
        answer[0] = 1;
        for (int i = 1; i < length; i++) {
            answer[i] = answer[i - 1] * nums[i - 1];
        }
        int p = 1;
        for (int i = length - 1; i >= 0; i--) {
            answer[i] = answer[i] * p;
            p *= nums[i];
        }
        return answer;
    }
}
